package com.example.chatroom.api;

import com.example.chatroom.model.Message;
import com.example.chatroom.model.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RestController
public class MessageAPI {
    @Autowired
    private MessageMapper mapper;

    @GetMapping("/message")
    public List<Message> getMessage(int sessionId) {
        List<Message> messageList = mapper.getMessageBySessionId(sessionId);

        Collections.reverse(messageList);
        return messageList;
    }
}
